'use strict';
exports.__esModule = true;
var mobx_state_tree_1 = require('mobx-state-tree');
// declaring the shape of a node with the type `Todo`
var Todo = mobx_state_tree_1.types.model({
  id: mobx_state_tree_1.types.number,
  title: mobx_state_tree_1.types.string,
  done: mobx_state_tree_1.types.boolean,
  assignee: mobx_state_tree_1.types.optional(
    mobx_state_tree_1.types.string,
    'nobody',
  ),
});
var TodoStore = mobx_state_tree_1.types
  // 1
  .model('TodoStore', {
    loaded: mobx_state_tree_1.types.boolean,
    endpoint: 'http://localhost',
    todos: mobx_state_tree_1.types.array(Todo),
    selectedTodo: mobx_state_tree_1.types.reference(Todo), // 5
  })
  .views(function(self) {
    return {
      // 6
      get completedTodos() {
        return self.todos.filter(function(t) {
          return t.done;
        });
      },
      // 7
      findTodosByUser: function(user) {
        return self.todos.filter(function(t) {
          return t.assignee === user;
        });
      },
    };
  })
  .actions(function(self) {
    return {
      addTodo: function(title) {
        self.todos.push({
          id: Math.random(),
          title: title,
          done: false,
        });
      },
    };
  });
var todoStore = TodoStore.create();
todoStore.addTodo('study vue');
todoStore.addTodo('study react');
todoStore.addTodo('study mobx');
console.dir(mobx_state_tree_1.getSnapshot(todoStore));
